package com.geek688.auxiliarytool.util;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;


public class PropertyUtil {
	
	static Logger log = LoggerFactory.getLogger(PropertyUtil.class);
	private static Properties properties = null;
	
	/**
	 * 加载外部配置文件
	 */
	public PropertyUtil(String path) {
		// 使用InPutStream流读取properties文件
		BufferedReader bufferedReader;
		try {
			properties = new Properties();
			bufferedReader = new BufferedReader(new InputStreamReader(new FileInputStream(path), "UTF-8"));
			properties.load(bufferedReader);
		} catch (FileNotFoundException e) {
			log.error("加载配置文件失败，找不到指定文件",e);
		} catch (IOException e) {
			log.error("加载配置文件异常",e);
		}
	}
	/**
	 * @Title loadJdbcProperties
	 * @description 加载jdbc数据类型映射文件
	 * @author Jack
	 * @date 2019-04-22
	 * @return
	 * return Properties
	 */
	public static Properties loadJdbcProperties() {
		Properties properties = new Properties();
		try {
			InputStream inputStream = ClassLoader.getSystemResourceAsStream("jdbc.properties");
			properties.load(inputStream);
		} catch (FileNotFoundException e) {
			log.error("加载配置文件失败，找不到指定文件",e);
		} catch (IOException e) {
			log.error("加载配置文件异常",e);
		}
		return properties;
	}
	
	public static String getProperty(String key) {
		return properties.getProperty(key);
	}
	
	public Properties getProperties() {
		return properties;
	}
}
